<?php 
	class Model_search extends CI_Model{
		protected $_table = "tbl_tours";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function count_all_search($name,$type,$price){
			if($name != NULL){
				$like_tour = "tour_name like '%".$name."%' and";
				$like_crui = "cruise_name like '%".$name."%' and";
			}else{
				$like_tour = "";
				$like_crui = "";
			}
			switch($type){
				case "1" : $sql = "select * from tbl_tours where ".$like_tour." cate_id = '52' and tour_status = '1' and tour_price $price"; 
					break;
				case "2" : $sql = "select * from tbl_cruises where ".$like_crui." cate_id = '88' and cruise_price $price";
					break;
				case "3" : $sql = "select * from tbl_tours where ".$like_tour." cate_id = '124' and tour_status = '1' and tour_price $price";
					break;
				default  : $sql = "select * from tbl_tours where ".$like_crui." cate_id = '52' and tour_status = '1' and tour_price $price"; 
					break;
			}
			$query = $this->db->query($sql);
			return $query->num_rows();
		}
		public function search($name,$type,$price,$off,$start){
			if($name != NULL){
				$like_tour = "tour_name like '%".$name."%' and";
				$like_crui = "cruise_name like '%".$name."%' and";
			}else{
				$like_tour = "";
				$like_crui = "";
			}
			switch($type){
				case "1" : $sql = "select * from tbl_tours where ".$like_tour." cate_id = '52' and tour_status = '1' and tour_price $price limit $start,$off"; 
					break;
				case "2" : $sql = "select * from tbl_cruises where ".$like_crui." cate_id = '88' and cruise_price $price limit $start,$off";
					break;
				case "3" : $sql = "select * from tbl_tours where ".$like_tour." cate_id = '124' and tour_status = '1' and tour_price $price limit $start,$off";
					break;
				default  : $sql = "select * from tbl_tours where ".$like_crui." cate_id = '52' and tour_status = '1' and tour_price $price limit $start,$off"; 
					break;
			}
			$query = $this->db->query($sql);
			return $query->result_array();
		}
		public function count_tours($keyw){
			$this->db->like("tour_name",$keyw);
			return $this->db->count_all_results($this->_table);
		}
		public function all_tours($keyw,$off,$start){
			$this->db->like("tour_name",$keyw);
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
	}